import { DailyAwardList } from "./DailyAwardList";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Language } from "../../../../../extend/language/Language";
import { DegreeRewardBody } from "./DegreeRewardBody";
import { GScrollPane } from "../../../../../com/mui/controls/GScrollPane";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { DailyInfo } from "../../../model/DailyInfo";
import { Cache } from "../../../cache/Cache";
type int = number;
//class ActiveDegreeRewardList
    
    export  class ActiveDegreeRewardList extends DailyAwardList
    {
        constructor(arg1: int, arg2: int)
        {
            super(arg1, arg2);
            return;
        }

        protected /* override */ initUI(): void
        {
            var loc1=null;
            _bg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            _bg.setSize(_width, _height);
            addChild(_bg);
            _bg = GlobalClass.getScaleBitmap(ImagesConst.RbListHeader);
            _bg.x = -2;
            _bg.y = -3;
            _bg.width = width + 9;
            _bg.height = 33;
            addChild(_bg);
            loc1 = new Object /* flash.text.TextField */();
            loc1.defaultTextFormat = new GTextFormat(FontUtil.lishuName, 20, 16774954);
            loc1.autoSize = flash.text.TextFieldAutoSize.CENTER;
            loc1.width = width - 8;
            loc1.x = width / 2;
            loc1.y = _bg.y + 5;
            loc1.textColor = 16774954;
            loc1.filters = [FilterConst.nameGlowFilter];
            loc1.text = Language.getString(20930);
            loc1.mouseEnabled = false;
            addChild(loc1);
            this._rewardBody = new DegreeRewardBody();
            this._scrollPane = new GScrollPane();
            this._scrollPane.x = 2;
            this._scrollPane.y = 30;
            this._scrollPane.width = width - 3;
            this._scrollPane.height = height - 32;
            this._scrollPane.styleName = "GScrollPane";
            this._scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._scrollPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPane.source = this._rewardBody;
            this._scrollPane.scrollDrag = false;
            addChild(this._scrollPane);
            return;
        }

        public /* override */ updateData(arg1: DailyInfo): void
        {
            return;
        }

        public updateReward(arg1: Array<any>): void
        {
            var loc2=0;
            var loc4=null;
            this.stopRewardFly();
            this._rewardBody.clear();
            var loc1=Cache.instance.daily.maxProcess;
            var loc3=arg1.length;
            while (loc2 < loc3) 
            {
                loc4 = arg1[loc2];
                if (loc1 < loc4.index) 
                {
                    break;
                }
                this._rewardBody.addItem(loc4);
                if (loc4.index > Cache.instance.daily.totalProcess) 
                {
                    this._rewardBody.filterItem(loc2, 1);
                }
                else if (loc4.index <= Cache.instance.daily.degreeReceived) 
                {
                    this._rewardBody.filterItem(loc2, 2);
                }
                else 
                {
                    this._rewardBody.filterItem(loc2);
                }
                ++loc2;
            }
            this._rewardBody.redraw();
            this._scrollPane.refreshPane();
            this._scrollPane.update();
            this._scrollPane.verticalScrollPosition = 0;
            return;
        }

        public updateProcess(): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            if (this._rewardBody.getItemNum() > 0) 
            {
                loc2 = this._rewardBody.getItemNum();
                while (loc1 < loc2) 
                {
                    loc3 = this._rewardBody.getItemAt(loc1).info;
                    if (loc3.index > Cache.instance.daily.totalProcess) 
                    {
                        this._rewardBody.filterItem(loc1, 1);
                    }
                    else if (loc3.index <= Cache.instance.daily.degreeReceived) 
                    {
                        this._rewardBody.filterItem(loc1, 2);
                    }
                    else 
                    {
                        this._rewardBody.filterItem(loc1);
                    }
                    ++loc1;
                }
            }
            return;
        }

        public onGetRewardRes(arg1: Array<any>): void
        {
            this.stopRewardFly();
            this._rewardList = arg1;
            this._rewardList.sort(Array.NUMERIC);
            this._scrollPane.verticalScrollPosition = 0;
            this._currentPosition = 0;
            this._currentIndex = 1;
            addEventListener(flash.events.Event.ENTER_FRAME, this.onFrameScript);
            return;
        }

        public stopRewardFly(): void
        {
            removeEventListener(flash.events.Event.ENTER_FRAME, this.onFrameScript);
            return;
        }

        /* internal  */onFrameScript(arg1: Object /* flash.events.Event */): void
        {
            this._scrollPane.verticalScrollPosition = this._scrollPane.verticalScrollPosition + 10;
            this._currentPosition = this._currentPosition + 10;
            if (this._currentPosition == 10 || this._currentPosition % 80 == 0) 
            {
                if (this.flyRewardIndex()) 
                {
                    this.flyRewardIndex();
                }
            }
            return;
        }

        /* internal  */flyRewardIndex(): Boolean
        {
            var loc1=this._rewardList.indexOf(this._currentIndex);
            if (loc1 != -1) 
            {
                this._rewardBody.onGetRewardRes(this._currentIndex);
            }
            if (this._currentIndex >= this._rewardList[(this._rewardList.length - 1)]) 
            {
                this.stopRewardFly();
                return false;
            }
            var loc2;
            var loc3=((loc2 = this)._currentIndex + 1);
            loc2._currentIndex = loc3;
            return true;
        }

        /* internal */ /* var */_scrollPane: GScrollPane;

        /* internal */ /* var */_rewardBody: DegreeRewardBody;

        /* internal */ /* var */_currentIndex: int;

        /* internal */ /* var */_rewardList: Array<any>;

        /* internal */ /* var */_currentPosition: int;
    }
